home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9468 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: mother.usf.edu!boheme!millert
  2. From: millert@boheme.csee.usf.edu (Timothy Miller)
  3. Newsgroups: comp.lang.c++
  4. Subject: copy vs. assignment
  5. Date: 1 Mar 1996 22:56:01 GMT
  6. Organization: University of South Florida
  7. Message-ID: <4h7va1$1ev@mother.usf.edu>
  8. NNTP-Posting-Host: 131.247.1.95
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Well, it seems that overloading the = operator for assigning one instance 
  12. of a class to one of its own kind is futile, because no matter what, it 
  13. uses the copy constructor to copy the class.
  14.  
  15. My problem is that I need to do one thing if an object is initialized by 
  16. one of its own kind, like this;
  17.  
  18. Matrix p;
  19. // stuff done to p;
  20. Matrix q = p;  // <- right here
  21.  
  22. And I need to do something else if an already existing object is being 
  23. assigned to like this:
  24.  
  25. Matrix p, q;
  26. // stuff done to p
  27. q = p;   // <- this should call a different class member
  28.  
  29. No matter what I do, it seems that q gets initialized by the 
  30. constructor, regardless of whether or not it's already been created, even 
  31. if I overload the = operator.
  32.  
  33. --
  34. ---------------------------------------------------------------------------
  35. Timothy Miller, millert@grad.csee.usf.edu           Theoretical Linguistics
  36. http://www.csee.usf.edu/~millert         Music Theory, Computer Engineering
  37. ---------------------------------------------------------------------------
  38. Cunning linguists are very skilled with their tongues.
  39.